using System;
using System.Collections;
using System.Collections.Generic;
using Miya.EmisssionLauncher;

using UnityEngine;

namespace Miya.EmisssionLauncher
{
    public class Emisson_RandomSector : Emission
    {
        public override EmissionData[] GetEmissions(bool _uselooper = true)
        {


            int thiscount = 0;

            if (_uselooper && (_CountLooper != null && _CountLooper.Count > 0))
                thiscount = _CountLooper.Next();
            else
                thiscount = Count;

            thiscount += _CountAddi;

            EmissionData[] _datas = new EmissionData[thiscount];

            if (thiscount <= 0) return _datas;

            int OO = 0;
            if (_uselooper && (_OffsetLooper != null && _OffsetLooper.Count > 0))
                OO = _OffsetLooper.Next();
            else
                OO = Offset;


            
            Vector3 op = Vector3.right * OO;

            //var steps = SpliteWidth(Width, thiscount);

            for (int i = 0; i < thiscount; i++)
            {
                Vector3 randomAxis;
                if (Width > 0)
                {
                    randomAxis = Vector3.up * UnityEngine.Random.value * Width;
                }
                else
                {
                    randomAxis = UnityEngine.Random.rotation.eulerAngles;
                }
                
                _datas[i] = new EmissionData()
                {
                    Owner = transform,
                    Position = Vector3.zero,
                    Direction = Quaternion.AngleAxis(OO + randomAxis.y, Vector3.up) * Vector3.forward,
                    Duration = this.Duration,
                };
            }
            return _datas;
        }

    }

}
